
class VerifyTheForm {
    /**
     * 构造函数，给所有的创建对象进行初始化
     * @param {String} textId 表示元素的id
     * @param {Function} fn 验证表单的函数
     */
    constructor(textId, fn) {
        this.input = document.querySelector("#" + textId);
        this.p = this.input.nextElementSibling;
        // this.value = this.input.value;
        this.fn = fn;
        // console.log(this.input, this.p, this.value);
        this.from = document.querySelector(".user-form");
        this.input.addEventListener("blur", () => {
            this.verify();
        })
    }

    /**
     * 用于验证表单
     */
    async verify() {
        let err = await this.fn(this.input.value)
        // console.log(err);
        if (err) {
            this.p.innerText = err;
            return false;
        } else {
            this.p.innerText = "";
            return true;
        }
    }
    static validationSucceeded(...pro) {
        let zhi = pro.map((item) => {
            let it = item.verify().then(data => { return data })
            return it;
        })
        let jg = Promise.all(zhi).then((data) => {
            let pd = data.every(item => {
                return item === true;
            })
            return pd;
        })
        return jg;
    }
}